package com.gbq.qimo.servlet;

import com.gbq.qimo.pojo.Student;
import com.gbq.qimo.pojo.Teacher;
import com.gbq.qimo.service.TeacherService;
import com.gbq.qimo.service.impl.TeacherServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @ClassName AddTeacherServlet
 * @Description TODO
 * @Author guobenqi
 * @Date 2021/6/5 18:04
 */
@WebServlet("/addTeacher")
public class AddTeacherServlet extends HttpServlet {
    private TeacherService teacherService = new TeacherServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Map<String, String[]> map = request.getParameterMap();
        Teacher teacher = new Teacher();
        try{
            BeanUtils.populate(teacher,map);
        }catch (IllegalAccessException e){
            e.printStackTrace();
        }catch (InvocationTargetException e){
            e.printStackTrace();
        }
        System.out.println(teacher);

        int count = teacherService.addTeacher(teacher);
        response.sendRedirect(request.getContextPath()+"/findStudentByPage");

    }
}
